<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑仓库类型</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var warehouseTypeId = Ext.create('Ext.form.field.Hidden', {
          name: 'id'
        });
        
        var name = Ext.create('Ext.form.field.Text', {
          fieldLabel: '名称',
          allowBlank: false,
          blankText: "仓库类型名称不能为空",
          name: 'name',
          anchor: '95%'
        });

        //提交按钮
        var submitButton = Ext.create('Ext.Button', {
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            if (editWarehouseTypeForm.form.isValid()) {
              editWarehouseTypeForm.form.submit({
                method: 'GET',
                success: function(result, response){
                  if (response.result.info == "成功") {
                    //添加成功后，隐藏窗口，并刷新Grid
                    editWarehouseTypeWin.destroy();
                  }
                  else {
                    Ext.MessageBox.alert('消息', response.result.info);
                  }
                },
                failure: function(result, response){
                  Ext.MessageBox.alert('提示', result.responseText);
                }
              });
            }
            else {
              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
            }
          }
        })

        //暂时保存按钮
        var closeButton = Ext.create('Ext.Button', {
          text: '关闭',
          tooltip: '关闭当前窗口，并且当前编辑的信息不能保存。',
          iconCls: 'exit',
          handler: function(){
            editWarehouseTypeWin.destroy();
          }
        });
        
        var editWarehouseTypeForm = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 55,
            labelAlign: 'right'
          },
          frame:true,
          url: '/warehouse_type/update?id=' + warehouseTypeId,
          reader: Ext.create('Ext.data.reader.Json',{
            model: 'WarehouseType',
            root: 'root'
          }),
          bodyStyle:'padding:5px 5px 0',
          width: 310,
          //height:300,
          items: [warehouseTypeId,name],
          buttons: [submitButton,closeButton]
        });
        //编辑前，把数据引入到表单中。
        editWarehouseTypeForm.form.load({
          url: '/warehouse_type/getWarehouseTypeById?id=<%=params[:id]%>',
          method : 'GET',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
          
        editWarehouseTypeForm.render('edit_warehouse_type_form');
      })
    </script>
  </head>
  <body>
    <div id="edit_warehouse_type_form"></div>
  </body>
</html>
